﻿using System;
using System.Diagnostics;
using Smarly.Idml.RelaxNg.Generator.Model;
using Tenuto.Grammar;

namespace Smarly.Idml.RelaxNg.Generator.Proxy
{
	public class OneOrMoreExpBuilder : Builder<OneOrMoreExp>
	{
		[DebuggerStepThrough]
		protected internal OneOrMoreExpBuilder(OneOrMoreExp exp, Action<IObjectName> updateName) : base(exp, updateName) { }

		public override IStruct CreateIStruct()
		{
			ListStruct result = new ListStruct();
			Factory(Exp.exp, UpdateName).Fill(result);
			return result;
		}

		public override IStruct Fill(IStruct getStruct)
		{
			getStruct = base.Fill(getStruct);

			if (getStruct is ListStruct)
			{
				var obj = (ListStruct) getStruct;

				obj.ObjectName = "OneOrMoreExpBuilder::Fill находить имя из типа";
				obj.IsNull = true;

				if (UpdateName != null) UpdateName(obj);
			}
			else
			{
				throw new NotImplementedException();
			}
			return getStruct;
		}
	}
}